{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit ConfigurationForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, GPSManager;

type
  TfrmGPSConfig = class(TForm)
    btClose: TButton;
    PageControl1: TPageControl;
    tsGeneral: TTabSheet;
    gbGPSSettings: TGroupBox;
    Label3: TLabel;
    Label5: TLabel;
    ecCOMPort: TComboBox;
    ecBaudRate: TComboBox;
    edUpdateInterval: TEdit;
    Label1: TLabel;
    udUpdateInterval: TUpDown;
    tsCameras: TTabSheet;
    gbCameraImport: TGroupBox;
    Label6: TLabel;
    edCameraFile: TEdit;
    btBrowseCamera: TButton;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure btCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    FGPS: TAHMGPSManager;
    procedure ShowGPSSettings;
    procedure UpdateGPSSettings;
  protected
    { Protected declarations }
    property GPSManager: TAHMGPSManager read FGPS write FGPS;
  public
    { Public declarations }
    class function Configure(GPS: TAHMGPSManager): Boolean;
  end;


implementation

{$R *.dfm}

uses Utilities, CPort;

procedure TfrmGPSConfig.Button1Click(Sender: TObject);
begin
//TODO - remove this (testing purposes only)
  with GPSManager.Cameras.Schema do
    if CheckSchema then
    begin
      PopulateTestData;
      BuildIndexes;
    end;
end;

class function TfrmGPSConfig.Configure(GPS: TAHMGPSManager): Boolean;
begin
  with Self.Create(nil) do
  try
    GPSManager := GPS;
    Result := (ShowModal = mrOK);
  finally
    Free;
  end;
end;

procedure TfrmGPSConfig.FormCreate(Sender: TObject);
begin
  // Populate list of known serial ports
  Screen.Cursor := crHourglass;
  try
    EnumerateSerialPorts(ecCOMPort.Items, nil);
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TfrmGPSConfig.FormShow(Sender: TObject);
begin
  // Display current configuration details
  ShowGPSSettings;
end;

procedure TfrmGPSConfig.btCloseClick(Sender: TObject);
begin
  // Update modified application settings
  UpdateGPSSettings;
end;

procedure TfrmGPSConfig.ShowGPSSettings;
begin
  // Update simple configuration items
  ecComPort.Text := FGPS.COMPort;
  ecBaudRate.ItemIndex := Integer(FGPS.BaudRate);
  udUpdateInterval.Position := FGPS.UpdateInterval;
end;

procedure TfrmGPSConfig.UpdateGPSSettings;
begin
  FGPS.COMPort := ecComPort.Text;
  FGPS.BaudRate := TBaudRate(ecBaudRate.ItemIndex);
  FGPS.UpdateInterval := udUpdateInterval.Position;
end;



end.
